package chapter_09_composite.p9_2;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by CharloYao on 2017/3/6.
 */
public class Folder implements Root {

    private String name;
    private List<Root> folder;

    public Folder(String name) {
        this.name = name;
        this.folder = new ArrayList<>();
    }

    @Override
    public boolean add(Root file) {
        folder.add(file);
        return true;
    }

    @Override
    public boolean remove(Root file) {
        folder.remove(file);
        return true;
    }

    @Override
    public void display() {
        System.out.println(this.name);
        for(Root root : folder){
            if(root instanceof Folder){
                System.out.print("|   ");
            }
            root.display();
        }
    }

    @Override
    public List<Root> getFile() {
        return folder;
    }
}
